deadlock prevention

 

            Ensure that the necessary conditions for deadlocks are never satisfied. Prevent one of the following from becoming true
– Mutual Exclusion
– Hold and Wait
– No Preemption
– Circular Wait

 

Mutual Exclusion

     

  1. Mutual exclusion is not a problem for sharable resources– an example is a “read-only” file which is     a resource that can be accessed simultaneously

  2. Problem: Some resources are inherently not sharable so, denying the mutual exclusion condition cannot be enforced in general

 

Hold-and-Wait

 

Guarantee that when a process requests a resource it does not hold any other resources.

 

  • Choice 1: A process requests and is allocated all of its resources before it begins execution
  • Choice 2: A process releases any resources it is holding before it requests for new ones
  • Choice 3: A process that is “holding” a resource immediately releases it if another of its requests cannot be satisfied currently
  • Limitations

– inefficient
– lowered resource utilization
– starvation

 

No Preemption

 

Take away resources from a process (preemption) and give them to another waiting process

  • some resources are preemptible
  • e.g., memory space, disk space (on a particular disk) these can be taken away from a process
  • Choices 1: If a process is holding some resources and requests other resources that cannot be granted to it, all of its resources are taken away
  • Choice 2: When a process requests additional resources, see if these resources are being held by a process that is itself waiting for new resources. In this situation, preempt the second process.
  • Limitations:
  • cost of preemption is high.
  • a process may get preempted even when there is no deadlock

 

Circular Wait

 

  1. The most common method of preventing deadlock is to prevent the circular wait.
  2. A simple way to do this, when possible, is to order the resources and always acquire them in order.
  3. Because a process can't be waiting on a lower numbered process while holding a higher numbered one, a cycle is impossible.
  4. Approaches that avoid circular waits include disabling interrupts during critical sections and using a hierarchy to determine a partial ordering of resources.
  5. If no obvious hierarchy exists, even the memory address of resources has been used to determine ordering and resources are requested in the increasing order of the enumeration. Dijkstra's solution can also be used.

 

deadlock by v. vanthana, dept of ca